package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    /**
     * 查询班级列表
     * @param empQueryParam
     * @return
     */
    @GetMapping
    public Result list(EmpQueryParam empQueryParam){
        log.info("请求参数： {}", empQueryParam);
        PageBean pageBean = clazzService.list(empQueryParam);
        return Result.success(pageBean);
    }

    /**
     * 新增班级
     * @param clazz
     * @return
     */
    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        log.info("新增班级，班级信息：{}", clazz);
        clazzService.save(clazz);

        return Result.success();
    }

    /**
     * 根据id查询班级信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("根据id查询班级信息，id：{}", id);
        Clazz clazz = clazzService.findById(id);
        return Result.success(clazz);
    }

    /**
     * 修改班级信息
     * @param clazz
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级，班级信息：{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    /**
     * 删除班级
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级，班级id：{}", id);
        clazzService.delete(id);
        return Result.success();
    }

    /**
     * 查询班级列表
     * @return
     */
    @GetMapping("/list")
    public Result clazzList(){
        List<Clazz> clazzList = clazzService.clazzList();

        return Result.success(clazzList);
    }


}
